<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Command-module for taskbar and icon tray access &mdash; Dragonfly-modules v0.1 documentation</title>
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '0.1',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="top" title="Dragonfly-modules v0.1 documentation" href="index.html" />
    <link rel="next" title="Command-module for direct opening of user-defined targets" href="mod-_bringme.html" />
    <link rel="prev" title="Command-module for command memory" href="mod-_cmdmemory.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="mod-_bringme.html" title="Command-module for direct opening of user-defined targets"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="mod-_cmdmemory.html" title="Command-module for command memory"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">Dragonfly-modules v0.1 documentation</a> &raquo;</li> 
      </ul>
    </div>  
    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  
  <div class="section" id="command-module-for-taskbar-and-icon-tray-access">
<h1>Command-module for <strong>taskbar</strong> and icon tray access<a class="headerlink" href="#command-module-for-taskbar-and-icon-tray-access" title="Permalink to this headline">¶</a></h1>
<p>This file implements commands for controlling tasks on the
taskbar and icons in the icon tray.</p>
<div class="section" id="commands">
<h2>Commands<a class="headerlink" href="#commands" title="Permalink to this headline">¶</a></h2>
<dl class="docutils">
<dt>Command: <strong>&#8220;[open | switch to] task &lt;number&gt;&#8221;</strong></dt>
<dd>Open the specified task on the taskbar.
The <em>&lt;number&gt;</em> extra is a number (1, 2, ...) designating which
task to activate.  The application on the taskbar which is
closest to the &#8220;Start&#8221; button is task <em>number 1</em>.  The next
is <em>number 2</em>, and so on.  This works for both horizontal and
vertical taskbars.</dd>
<dt>Command: <strong>&#8220;&lt;action&gt; task &lt;number&gt;&#8221;</strong></dt>
<dd><p class="first">Similar to the command above, but performs some action
under specified task.  The following actions are available:</p>
<blockquote class="last">
<ul class="simple">
<li><strong>&#8220;(menu | pop up)&#8221;</strong> &#8211; show the pop-up menu of the task,
as if a right-click was done on the taskbar.</li>
<li><strong>&#8220;(maximize | max)&#8221;</strong> &#8211; maximize the task.</li>
<li><strong>&#8220;(minimize | min)&#8221;</strong> &#8211; minimize the task.</li>
<li><strong>&#8220;restore&#8221;</strong> &#8211; restore the task.</li>
<li><strong>&#8220;close&#8221;</strong> &#8211; close the task.</li>
</ul>
</blockquote>
</dd>
<dt>Command: <strong>&#8220;[open] icon &lt;number&gt;&#8221;</strong></dt>
<dd>Open the specified icon in the icon tray.
The <em>&lt;number&gt;</em> extra is a number (1, 2, ...) designating which
icon to activate.  The numbering is similar to that explained
above for tasks on the taskbar.</dd>
<dt>Command: <strong>&#8220;(menu | pop up) icon &lt;number&gt;&#8221;</strong></dt>
<dd>Pop-up the menu for the specified icon in the icon tray.</dd>
</dl>
</div>
<div class="section" id="usage-examples">
<h2>Usage examples<a class="headerlink" href="#usage-examples" title="Permalink to this headline">¶</a></h2>
<p>Several concrete usage examples of the commands described above:</p>
<blockquote>
<ul class="simple">
<li>Say <strong>&#8220;task 4&#8221;</strong> to bring the fourth application on the taskbar
to the foreground.</li>
<li>Say <strong>&#8220;close task 2&#8221;</strong> to close the second application on
the taskbar.</li>
<li>Say <strong>&#8220;icon 1&#8221;</strong> to activate the first icon visible in the
icon tray, as if it was double-clicked.</li>
<li>Say <strong>&#8220;pop up icon 3&#8221;</strong> to bring up the menu of the third
icon visible in the icon tray, as if it was right-clicked.</li>
</ul>
</blockquote>
</div>
<div class="section" id="module-source-code">
<h2>Module source code<a class="headerlink" href="#module-source-code" title="Permalink to this headline">¶</a></h2>
<p>The most current version of this module can be downloaded from the <a class="reference external" href="http://dragonfly-modules.googlecode.com/svn/trunk/command-modules/_taskbar.py">repository here</a>.</p>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><pre>  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117</pre></td><td class="code"><div class="highlight"><pre><span class="c">#</span>
<span class="c"># This file is a command-module for Dragonfly.</span>
<span class="c"># (c) Copyright 2008 by Christo Butcher</span>
<span class="c"># Licensed under the LGPL, see &lt;http://www.gnu.org/licenses/&gt;</span>
<span class="c">#</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Command-module for **taskbar** and icon tray access</span>
<span class="sd">===================================================</span>
<span class="sd">This file implements commands for controlling tasks on the</span>
<span class="sd">taskbar and icons in the icon tray.</span>

<span class="sd">Commands</span>
<span class="sd">--------</span>

<span class="sd">Command: **&quot;[open | switch to] task &lt;number&gt;&quot;**</span>
<span class="sd">    Open the specified task on the taskbar.</span>
<span class="sd">    The *&lt;number&gt;* extra is a number (1, 2, ...) designating which</span>
<span class="sd">    task to activate.  The application on the taskbar which is</span>
<span class="sd">    closest to the &quot;Start&quot; button is task *number 1*.  The next</span>
<span class="sd">    is *number 2*, and so on.  This works for both horizontal and</span>
<span class="sd">    vertical taskbars.</span>

<span class="sd">Command: **&quot;&lt;action&gt; task &lt;number&gt;&quot;**</span>
<span class="sd">    Similar to the command above, but performs some action</span>
<span class="sd">    under specified task.  The following actions are available:</span>

<span class="sd">     - **&quot;(menu | pop up)&quot;** -- show the pop-up menu of the task,</span>
<span class="sd">       as if a right-click was done on the taskbar.</span>
<span class="sd">     - **&quot;(maximize | max)&quot;** -- maximize the task.</span>
<span class="sd">     - **&quot;(minimize | min)&quot;** -- minimize the task.</span>
<span class="sd">     - **&quot;restore&quot;** -- restore the task.</span>
<span class="sd">     - **&quot;close&quot;** -- close the task.</span>

<span class="sd">Command: **&quot;[open] icon &lt;number&gt;&quot;**</span>
<span class="sd">    Open the specified icon in the icon tray.</span>
<span class="sd">    The *&lt;number&gt;* extra is a number (1, 2, ...) designating which</span>
<span class="sd">    icon to activate.  The numbering is similar to that explained</span>
<span class="sd">    above for tasks on the taskbar.</span>

<span class="sd">Command: **&quot;(menu | pop up) icon &lt;number&gt;&quot;**</span>
<span class="sd">    Pop-up the menu for the specified icon in the icon tray.</span>

<span class="sd">Usage examples</span>
<span class="sd">--------------</span>

<span class="sd">Several concrete usage examples of the commands described above:</span>

<span class="sd"> - Say **&quot;task 4&quot;** to bring the fourth application on the taskbar</span>
<span class="sd">   to the foreground.</span>
<span class="sd"> - Say **&quot;close task 2&quot;** to close the second application on</span>
<span class="sd">   the taskbar.</span>
<span class="sd"> - Say **&quot;icon 1&quot;** to activate the first icon visible in the</span>
<span class="sd">   icon tray, as if it was double-clicked.</span>
<span class="sd"> - Say **&quot;pop up icon 3&quot;** to bring up the menu of the third</span>
<span class="sd">   icon visible in the icon tray, as if it was right-clicked.</span>

<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">pkg_resources</span>
<span class="n">pkg_resources</span><span class="o">.</span><span class="n">require</span><span class="p">(</span><span class="s">&quot;dragonfly &gt;= 0.6.5beta1.dev-r76&quot;</span><span class="p">)</span>

<span class="kn">from</span> <span class="nn">dragonfly</span> <span class="kn">import</span> <span class="p">(</span><span class="n">Grammar</span><span class="p">,</span> <span class="n">MappingRule</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">Key</span><span class="p">)</span>


<span class="c">#---------------------------------------------------------------------------</span>
<span class="c"># This rule controls tasks on the taskbar.</span>

<span class="k">class</span> <span class="nc">TaskRule</span><span class="p">(</span><span class="n">MappingRule</span><span class="p">):</span>

    <span class="n">mapping</span> <span class="o">=</span> <span class="p">{</span>
               <span class="s">&quot;[open | switch to] task &lt;n&gt;&quot;</span><span class="p">:</span>  <span class="n">Key</span><span class="p">(</span><span class="s">&quot;space&quot;</span><span class="p">),</span>
               <span class="s">&quot;(menu | pop up) task &lt;n&gt;&quot;</span><span class="p">:</span>     <span class="n">Key</span><span class="p">(</span><span class="s">&quot;apps&quot;</span><span class="p">),</span>
               <span class="s">&quot;close task &lt;n&gt;&quot;</span><span class="p">:</span>               <span class="n">Key</span><span class="p">(</span><span class="s">&quot;apps/10, c&quot;</span><span class="p">),</span>
               <span class="s">&quot;restore task &lt;n&gt;&quot;</span><span class="p">:</span>             <span class="n">Key</span><span class="p">(</span><span class="s">&quot;apps/10, r&quot;</span><span class="p">),</span>
               <span class="s">&quot;(minimize | min) task &lt;n&gt;&quot;</span><span class="p">:</span>    <span class="n">Key</span><span class="p">(</span><span class="s">&quot;apps/10, n&quot;</span><span class="p">),</span>
               <span class="s">&quot;(maximize | max) task &lt;n&gt;&quot;</span><span class="p">:</span>    <span class="n">Key</span><span class="p">(</span><span class="s">&quot;apps/10, x&quot;</span><span class="p">),</span>
              <span class="p">}</span>
    <span class="n">extras</span>  <span class="o">=</span> <span class="p">[</span><span class="n">Integer</span><span class="p">(</span><span class="s">&quot;n&quot;</span><span class="p">,</span> <span class="mf">1</span><span class="p">,</span> <span class="mf">12</span><span class="p">)]</span>

    <span class="k">def</span> <span class="nf">_process_recognition</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">extras</span><span class="p">):</span>
        <span class="n">count</span> <span class="o">=</span> <span class="n">extras</span><span class="p">[</span><span class="s">&quot;n&quot;</span><span class="p">]</span> <span class="o">-</span> <span class="mf">1</span>
        <span class="n">action</span> <span class="o">=</span> <span class="n">Key</span><span class="p">(</span><span class="s">&quot;w-b/10, s-tab/10, right:</span><span class="si">%d</span><span class="s">/10&quot;</span> <span class="o">%</span> <span class="n">count</span><span class="p">)</span> <span class="o">+</span> <span class="n">value</span>
        <span class="n">action</span><span class="o">.</span><span class="n">execute</span><span class="p">()</span>


<span class="c">#---------------------------------------------------------------------------</span>
<span class="c"># This rule controls icons in the icon tray.</span>

<span class="k">class</span> <span class="nc">IconRule</span><span class="p">(</span><span class="n">MappingRule</span><span class="p">):</span>

    <span class="n">mapping</span> <span class="o">=</span> <span class="p">{</span>
               <span class="s">&quot;[open] icon &lt;n&gt;&quot;</span><span class="p">:</span>              <span class="n">Key</span><span class="p">(</span><span class="s">&quot;enter&quot;</span><span class="p">),</span>
               <span class="s">&quot;(menu | pop up) icon &lt;n&gt;&quot;</span><span class="p">:</span>     <span class="n">Key</span><span class="p">(</span><span class="s">&quot;apps&quot;</span><span class="p">),</span>
              <span class="p">}</span>
    <span class="n">extras</span>  <span class="o">=</span> <span class="p">[</span><span class="n">Integer</span><span class="p">(</span><span class="s">&quot;n&quot;</span><span class="p">,</span> <span class="mf">1</span><span class="p">,</span> <span class="mf">12</span><span class="p">)]</span>

    <span class="k">def</span> <span class="nf">_process_recognition</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">extras</span><span class="p">):</span>
        <span class="n">count</span> <span class="o">=</span> <span class="n">extras</span><span class="p">[</span><span class="s">&quot;n&quot;</span><span class="p">]</span> <span class="o">-</span> <span class="mf">1</span>
        <span class="n">action</span> <span class="o">=</span> <span class="n">Key</span><span class="p">(</span><span class="s">&quot;w-b/10, right:</span><span class="si">%d</span><span class="s">/10&quot;</span> <span class="o">%</span> <span class="n">count</span><span class="p">)</span> <span class="o">+</span> <span class="n">value</span>
        <span class="k">print</span> <span class="s">&quot;executing&quot;</span><span class="p">,</span> <span class="n">action</span>
        <span class="n">action</span><span class="o">.</span><span class="n">execute</span><span class="p">()</span>


<span class="c">#---------------------------------------------------------------------------</span>
<span class="c"># Load the grammar instance and define how to unload it.</span>

<span class="n">grammar</span> <span class="o">=</span> <span class="n">Grammar</span><span class="p">(</span><span class="s">&quot;taskbar&quot;</span><span class="p">)</span>
<span class="n">grammar</span><span class="o">.</span><span class="n">add_rule</span><span class="p">(</span><span class="n">TaskRule</span><span class="p">())</span>
<span class="n">grammar</span><span class="o">.</span><span class="n">add_rule</span><span class="p">(</span><span class="n">IconRule</span><span class="p">())</span>
<span class="n">grammar</span><span class="o">.</span><span class="n">load</span><span class="p">()</span>

<span class="c"># Unload function which will be called by natlink at unload time.</span>
<span class="k">def</span> <span class="nf">unload</span><span class="p">():</span>
    <span class="k">global</span> <span class="n">grammar</span>
    <span class="k">if</span> <span class="n">grammar</span><span class="p">:</span> <span class="n">grammar</span><span class="o">.</span><span class="n">unload</span><span class="p">()</span>
    <span class="n">grammar</span> <span class="o">=</span> <span class="bp">None</span>
</pre></div>
</td></tr></table></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">Command-module for <strong>taskbar</strong> and icon tray access</a><ul>
<li><a class="reference external" href="#commands">Commands</a></li>
<li><a class="reference external" href="#usage-examples">Usage examples</a></li>
<li><a class="reference external" href="#module-source-code">Module source code</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="mod-_cmdmemory.html" title="previous chapter">Command-module for <strong>command memory</strong></a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="mod-_bringme.html" title="next chapter">Command-module for direct opening of <strong>user-defined targets</strong></a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="_sources/mod-_taskbar.txt">Show Source</a></li>
            </ul>
          <h3>Quick search</h3>
            <form class="search" action="search.html" method="get">
              <input type="text" name="q" size="18" /> <input type="submit" value="Go" />
              <input type="hidden" name="check_keywords" value="yes" />
              <input type="hidden" name="area" value="default" />
            </form>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="mod-_bringme.html" title="Command-module for direct opening of user-defined targets"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="mod-_cmdmemory.html" title="Command-module for command memory"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">Dragonfly-modules v0.1 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2008, Christo Butcher.
      Last updated on Apr 10, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.5.1.
    </div>
  </body>
</html>